import Vue from 'vue'
import Vuex from 'store'

import {RouterMount,createRouter} from 'uni-simple-router';

const router = createRouter({
	platform: process.env.VUE_APP_PLATFORM,  
	routes: [...ROUTES]
});

let whiteList = [
	'/pages/index/index','/pages/index/detail','/pages/my/my','/pages/my/auth'
]

//全局路由前置守卫
router.beforeEach((to, from, next) => {
	// 定时更新请求用户数据
	// uni.setStorageSync('prev_path',from.pullPath)
	if(Vuex.getters.login){
		// 检测用户信息
		next();
	}else{ // 清空
		Vuex.commit('logout');
		if(whiteList.includes(to.path)){
			console.log(2);
			next();
		}else{
			console.log(1);
			uni.setStorageSync('prev_path',from.fullPath)
			next({
				path: '/pages/my/auth'
			})
		}
	}
});

// 全局路由后置守卫
router.afterEach((to, from) => {
    console.log('跳转结束')
})

export {
	router,
	RouterMount
}